//
//  InputToolBar.m
//  SinaWeibo
//
//  Created by Apple on 16/8/17.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "InputToolBar.h"

@implementation InputToolBar


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
        
        [self setupToolbar];
        
    }
    return self;
    
}

-(void)setupToolbar{
    
    [self addToolBtnWithImgName:@"compose_toolbar_picture"];
    
    [self addToolBtnWithImgName:@"compose_mentionbutton_background"];
    
    [self addToolBtnWithImgName:@"compose_trendbutton_background"];
    
    [self addToolBtnWithImgName:@"compose_emoticonbutton_background"];
    
    [self addToolBtnWithImgName:@"compose_keyboardbutton_background"];
    
    
    
    
}

-(void)addToolBtnWithImgName:(NSString *)imgName{
    
    //创建一个Btn
    UIButton *toolBtn = [[UIButton alloc]init];
    
    //设置正常和高亮状态图片
    [toolBtn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    
    NSString *highlightedImgName = [imgName stringByAppendingString:@"_highlighted"];
    
    [toolBtn setImage:[UIImage imageNamed:highlightedImgName] forState:UIControlStateHighlighted];
    
    
    //添加点击事件
    [toolBtn addTarget:self action:@selector(clickToolBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    //添加到self 上.
    
    [self addSubview:toolBtn];
    
}


-(void)clickToolBtn:(UIButton *)toolBtn{
    
    NSLog(@"'clickToolBtn");
    
}



-(void)layoutSubviews{
    
    //设置frame
    
    NSInteger count = self.subviews.count;
    
    for (int i = 0 ; i<count; i++) {
        
        
        CGFloat W = self.frame.size.width / count ;
        CGFloat H = self.frame.size.height;
        CGFloat x = i * W ;
        CGFloat y = 0;
        
        self.subviews[i].frame = CGRectMake(x, y,W, H);
    }
    [self sizeToFit];
    
    
}


@end
